<template>
  <div id="app">
    <h2>测试题</h2>
    <SubjectItem @submitFn="submitFn2"></SubjectItem>
    <div>
      <FlagItem :statusArr="statusArr"></FlagItem>
    </div>
  </div>
</template>

<script>
import FlagItem from "./components/FlagItem.vue";
import SubjectItem from "./components/SubjectItem.vue";

export default {
  data() {
    return {
      statusArr: [],
      idlist:[]
    };
  },
  components: {
    FlagItem,
    SubjectItem,
  },
  methods: {
    submitFn2(val1, val2,id) {
      // if(!this.idlist.length) {
      //   this.idlist.push(id)
      // }
      // console.log(id)
       // 遍历this.idlist数组
    for (let i = 0; i < this.idlist.length; i++) {
      // 如果找到相同的id
      if (this.idlist[i] === id) {
        // 打印消息并跳出方法
        console.log('没通过');
        return;
      }
    }
    // 如果没有找到相同的id，将其添加到数组中
    this.idlist.push(id);
      // console.log(this.idlist.toString())
      // if(this.idlist.includes(id)) return console.log('没通过')
      // this.idlist.push(id)
      console.log(this.idlist)
      console.log(val1, val2)
      if (val1 === val2) {
        this.statusArr.push({
          cont: "回答正确",
          classAttr: "right",
        });
      } else if (val1 !== val2) {
        if (val2 === undefined) {
          this.statusArr.push({
            cont: "未完成",
            classAttr: "undo",
          });
        } else {
          this.statusArr.push({
            cont: "回答错误",
            classAttr: "error",
          });
        }
      }
    },
  },
};
</script>

<style>
body {
  background-color: #eee;
}

#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
</style>
